import { setSpritesheetMap, getSpritesheetMap } from '@renderer/store/modules/usePixiStore'
import * as PIXI from 'pixi.js'
export default async (assetsName: string): Promise<PIXI.Spritesheet> => {
  let assets = getSpritesheetMap(assetsName)
  if (!assets) {
    const path = await window.api.getAsset(`/sprite/${assetsName}.json`)
    await PIXI.Assets.load([path])
    assets = PIXI.Assets.cache.get(path) as PIXI.Spritesheet
    setSpritesheetMap(assetsName, assets)
  }
  return assets
}
